package com.lemon.smartsafetynew.ui.activity.contact;

import android.os.Bundle;
import android.widget.TextView;

import com.lemon.android.http.HttpUtils;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.ApplicationInfo;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.ImgLoadUtil;
import com.lemon.smartsafetynew.entity.contact.PersonVo;
import com.lemon.smartsafetynew.util.common.CallUtils;
import com.lemon.smartsafetynew.util.constants.KeyConstants;

import butterknife.Bind;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 联系人详情
 * Created by Andrew on 2017/9/18.
 */

public class ContactDetailActivity extends SwipeBackActivity {

    @Bind(R.id.user_icon_imageView)
    CircleImageView userIconImageView;
    @Bind(R.id.user_name_tv)
    TextView userNameTv;
    @Bind(R.id.department_tv)
    TextView departmentTv;
    @Bind(R.id.job_tv)
    TextView jobTv;
    @Bind(R.id.telephone_tv)
    TextView telephoneTv;

    private PersonVo personVo;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();

        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            personVo = (PersonVo) bundle.get(KeyConstants.KEY_PERSON);
        }
    }

    @Override
    protected void initTitle() {
        this.setBarTitle(getString(R.string.contact_detail_str));
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(ContactDetailActivity.this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_contact_detail;
    }

    @Override
    protected void initViews() {
        super.initViews();

        if (!CommonUtil.strIsEmpty(personVo.getPhotoURL())) {
            try {
                ImgLoadUtil.setImgPath(HttpUtils.formatFilesUrl(personVo.getPhotoURL()), userIconImageView);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            userIconImageView.setBackgroundResource(R.mipmap.img_placeholder);
        }

        userNameTv.setText(com.lemon.smartsafetynew.util.common.CommonUtil.avoidNullString(personVo.getUser_name()));
        departmentTv.setText(com.lemon.smartsafetynew.util.common.CommonUtil.avoidNullString(personVo.getDepartment_name()));
        jobTv.setText(ApplicationInfo.userTypeMap.get(personVo.getUser_type()));
        telephoneTv.setText(com.lemon.smartsafetynew.util.common.CommonUtil.avoidNullString(personVo.getMobile()));
    }

    @OnClick(R.id.telephone_tv)
    public void onViewClicked() {

        if("无".equals(telephoneTv.getText().toString().trim())) {
            //TODO
        } else {
            CallUtils.jumpCallTelPage(telephoneTv.getText().toString().trim());
        }


    }
}
